//
// Created by REEJI2219 on 2024-09-29.
//
#include <iostream>
using namespace std;
typedef int ElemType;
class Node {
public:
    ElemType data;
    Node *next;
};
class NoHeadLinkList {
public:
    Node *head;
    NoHeadLinkList() {
        head = nullptr;
    }
    ~NoHeadLinkList() {
        Node *deleteNode = head;
        //删除非头节点
        while (head->next) {
            deleteNode = head;
            head=head->next;
            delete deleteNode;
        }
        delete head;
    }
    /**
     * 无头节点插入
     * @param data 数据元素
     */
    void insert(ElemType data) {
        Node *node = new Node();
        node->data=data;
        node->next=nullptr;
        if(head==nullptr) {
            head=node;
        }else {
            Node *current = head;
            while (current->next!=nullptr) {
                current = current->next;
            }
            current->next =node;
        }

    }
};